package kuzha.runtime;

import java.util.Map;

import kuzha.KuzhaObject;

public class NumberPattern extends CasePattern {
	public final Number value;
	
	private NumberPattern(Number value) {
		if (value == null)
			throw new IllegalArgumentException();
		this.value = value;
	}
	
	public static NumberPattern valueOf(Number value) {
		return new NumberPattern(value);
	}
	
	@Override
	public boolean match(KuzhaObject value, Map<String, KuzhaObject> vars) {
		if (this.value instanceof Integer) {
			return value instanceof KzInt32 && ((KzInt32)value).value == this.value.intValue();
		}
		else if (this.value instanceof Long) {
			return value instanceof KzInt64 && ((KzInt64)value).value == this.value.longValue();
		}
		else if (this.value instanceof Float) {
			return value instanceof KzFloat32 && ((KzFloat32)value).value == this.value.floatValue();
		}
		else if (this.value instanceof Double) {
			return value instanceof KzFloat64 && ((KzFloat64)value).value == this.value.doubleValue();
		}
		return false;
	}
}
